import type { FormRule } from 'antd';
import { FormSchema } from './types'; // 自定义类型定义

export interface FormItem extends FormSchema {
  componentProps?: Record<string, any>;
}

// 表格列配置
export const columns = [
  {
    title: '班组名称',
    dataIndex: 'name',
    width: 150,
    ellipsis: true,
    align: 'center' as const,
  },
  {
    title: '操作',
    dataIndex: 'action',
    align: 'center' as const,
    fixed: 'right' as const,
    width: 250,
    render: (_: any, record: any) => (
      // 操作列的渲染逻辑在父组件中实现
      <span className="action-buttons">{/* 操作按钮 */}</span>
    ),
  },
];

// 搜索表单配置
export const search: FormItem[] = [
  {
    label: '班组名称',
    name: 'name',
    component: 'Input',
    span: 6,
    componentProps: {
      maxLength: 50,
      placeholder: '请输入班组名称',
    },
  },
];

export const formConfig = [
  {
    label: '班组名称',
    field: 'name',
    component: 'Input',
    span: 24,
    show: true,
    componentProps: {
      maxlength: 50,
      placeholder: '请输入班组名称',
    },
  },
  {
    label: '关联用户',
    field: 'userIdList',
    component: 'ApiSelect',
    span: 24,
    show: true,
    componentProps: {
      maxlength: 50,
      placeholder: '请选择关联用户',
      mode: 'multiple',
      option: [
        {
          label: '用户1',
          value: '1',
        },
        {
          label: '用户2',
          value: '2',
        },
      ],
    },
  },
];

export const rules = {
  // name: [{ required: true, trigger: 'change' }],
  // userIdList: [
  //   {
  //     required: true,
  //     trigger: 'change',
  //     validator: (_, value) => {
  //       return new Promise((resolve, reject) => {
  //         if (!value) {
  //           reject(new Error('请选择关联用户'));
  //         } else {
  //           resolve();
  //         }
  //       });
  //     },
  //   },
  // ],
};
